David Karlins
Introduction
This lesson explores two dimensions of advanced HTML5 and CSS3. One is creating slide shows, which are one of the most widely used elements of attractive, inviting Web pages. The other is integrating JavaScript widgets, which allow designers to implement JavaScript animation and interactivity without writing any JavaScript code.
JavaScript is the dominant language for client-side website scripts—scripts that run in browsers. You can use JavaScript to create animation (elements that move around a page). You can also use it to create interactivity (elements that respond to user actions, like a click or hovering with a mouse). JavaScript runs in any browser and on any operating system, so it's essential to modern, dynamic, inviting websites.
JavaScript is more difficult to learn than HTML or CSS, but that doesn't mean it's impossible. And after learning how it works in this lesson, you may want to sign up for a JavaScript class at the institution through which you enrolled in this course.
JavaScript-based objects take a lot of work to build, even for skilled coders. It isn't worth it for everyone who wants to use a slide show to learn enough JavaScript to build a slide-show template. Instead, individual coders or teams of JavaScript coders build templates for commonly used interactive objects, such as slide shows, menu bars, or pop-up tool tips that provide text descriptions for content when a mouse hovers over it.
Advanced HTML5 and CSS3 coders use JavaScript widgets. These sets of files include JavaScript, HTML, and CSS files. You can customize the content of the widget by editing the HTML, and you can customize the look and feel of the widget by editing the CSS. It is not necessary, expected, or generally a good idea to try to edit the JavaScript itself when you're using a widget.
We'll return to how JavaScript relates to jQuery in the next chapter, but in brief: jQuery is a set of prepackaged JavaScript codes that scripters use to build widgets. A team maintains and distributes the jQuery library from jquery.com. A larger community of JavaScript coders takes advantage of jQuery to build widgets more efficiently.
Where do designers fit into this picture? We're the consumers, so to speak. We use widgets that JavaScript coders have built, and we customize their content with HTML and CSS.
Please join me in Chapter 2, where we'll talk about how you can use scripts in general and JavaScript in particular.
How Designers Use Scripts
Let's step back and examine the role of scripts in general, not just JavaScript. Scripts are short programs in languages like PHP or JavaScript. We saw an example of PHP scripting in Lesson 7, when we generated a PHP script and used it to handle data in a form.
Let's review what you learned from that experience:
I think it's helpful to review that process because, as you wield HTML5 and CSS3 in complex sites, you're going to interact with scripting. There's no need to mystify that process: Someone creates the script, you link to it, you follow the documentation that comes with the script, and you alter the HTML and CSS to make it do what you want and to make it blend into your site.
Here's another generalization we can make about connecting with scripts: They come in packages that include HTML and CSS. Remember, the PHP script we got from TheSiteWizard back in Lesson 7 came with HTML that we had to copy and paste into our page to create a form that meshed with the PHP script.
Many times, the package of script plus HTML (and sometimes CSS as well) is called a widget. Widgets, in other words, can be sets of script, HTML, and CSS.
The Role of JavaScript
JavaScript is a language that programmers use to create animation and interactivity in Web pages. As I noted in the introduction, JavaScript is a client-side scripting language. That means the JavaScript runs on a user's computer, not on a server. In contrast, PHP, Ruby, Ruby on Rails, Perl, and other scripting runs on servers.
By the way, JavaScript is actually unrelated to the Java programming language. Someone thought it would improve the "branding" of this language to associate it with Java, and that's how JavaScript got its name.
As the HTML5 and CSS3 design community grows and matures, more JavaScript content is available in easy-to-use widgets.
The World of JavaScript Interactivity and Animation
Let's quickly look at some design elements that people often use JavaScript for:
An accordion widget
A vertical menu bar
Tabs
In the Supplementary Material for this lesson, I'll provide you with links to grab the code for these and other JavaScript-based widgets.
What Is jQuery?
jQuery is essentially a set of packaged chunks of JavaScript code that allow JavaScript developers to write less code. jQuery works in all browsers, even Internet Explorer 6. And it works with older versions of HTML as well as with HTML5. You can find the jQuery JavaScript code at jquery.com.
jQuery widgets generally require at least three JavaScript scripts:
For example, the jQuery widget I used to create the tab panel we just looked at has these script elements. They go in the <head> tag of an HTML page:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script> <script> $(function() { $( "#tabs" ).tabs(); }); </script>
The first line links to the main jQuery script. The second <script> element links to a specific jQuery module that makes the tab widget work. And the third script isn't a link; it's a bit of JavaScript that has to go inside the page itself to make the widget work.
How Do You Use jQuery Widgets?
Now that you're getting a sense of how easy it is to implement jQuery widgets, you may be asking yourself, "How do I use these things?"
The answer is a four-step process:
Designers don't edit the centrally distributed jQuery code. That code resides permanently at the jquery.com site. And usually the JavaScript in jQuery widgets doesn't require editing either. Designers customize jQuery widgets by editing the HTML, and sometimes CSS, that comes with jQuery widgets.
Let's move on to Chapter 3, where I'll introduce you to some JavaScript slide shows.
Surveying JavaScript and jQuery Slide Shows
A whole range of JavaScript slide shows is available online. I'll share links to a few of my favorites in the Supplementary Material, and you can find more by searching for "javascript slide shows."
Some of the widgets you'll find cost money to download and use. Others are free. Guess which kind we're going to explore here? If you said free, you guessed right.
Many valuable jQuery widgets sell for under $100. (Most of those have licenses for one-site usage.) I'll provide information on commercial distribution of jQuery widgets in the Supplementary Material section.
There are times and places for slide shows that jump off the screen. These slide shows often include dramatic transitions from slide to slide, sound effects, and more. At other times, it's more appropriate to use a modest template that blends gracefully with your page.
Let's check out a couple examples of online, free, JavaScript slide show templates.
The first is the Wow Slider. This is a popular JavaScript-based slide show generator. It's not free, but we can look at it for free. Go to http://wowslider.com/demo.html to see examples of the kinds of slide shows you can generate with the Wow Slider application.
Testing the Wow Slider
Next let's jump over to a more subtle example—slidesjs, at http://slidesjs.com. This template is simpler, with minimalist effects and navigation.
Testing the slidesjs slide show example
While the SlidesJS template is simple, it works well, and once you know how to install it, you can install any other JavaScript slide show. In fact, you can use the technique for downloading and customizing the SlidesJS widget on any jQuery widget, from tabbed panels to menu bars.
Downloading a Basic jQuery Slide Show Template
To use and customize the SlidesJS widget, we'll download it, save it to the site we're using for all our class site content, and then customize it with our own pictures and styling.
To download the widget, follow these steps:
Downloading files for the slidesjs slide show
Extracting folders for the slidesjs slide show
Testing the downloaded slide show
Testing the downloaded sample slide show
Did it work? If not, please ask me about it in the Discussion Area. I'm always glad to help you.
Customizing and Adding Slides
Obviously designers want to replace the placeholder images that come with the SlidesJS widget!
You can do that by saving your own images to the img folder that's within the standard folder. But to avoid corrupting the JavaScript that makes the SlidesJS widget work, rename your images to match the filenames in the jQuery widget template. In this case, those filenames are: example-slide-1.jpg, example-slide-2.jpg, example-slide-3.jpg, and example-slide-4.jpg.
Customizing images for the slide show
Periodically refresh your browser to see how the images look.
Here are a few tips:
If you need some images, you can download these.
Download Images Here
Customizing CSS
Now that we've customized the images in the slide show, let's apply our own custom style sheet to the file. To do that, follow these steps:
<link href="../../../style.css" rel="stylesheet" type="text/css">
By the way, the three sets of "../" before our style sheet name tell a browser to look three levels up in the site's folder structure for the linked style sheet.
We placed our style sheet link at the end of the list so that our styles will "trump" (override) any earlier styling in the style sheets we linked to in the sample.
Customizing HTML
With our CSS file attached to the slide show HTML page, we can customize the page's content.
<title>Watch our slide show!</title>
<div id="wrapper"> <div id="banner"> <h1>Check out our slide show!</h1> </div>
</div>
<div class="container">
Adding Images
Did you copy more than four images into the img folder? If so, let's fix the code so that those additional images become visible.
<img src="img/example-slide-5.jpg" alt="Photo by me!">
You can also add <img> elements like the one above but with sequentially higher numbers for the slides ("img/example-slide-6.jpg," "img/example-slide-7.jpg," and so on).
Again, you can use your own photos here if you wish. I did in the example below. Or you can use the flower images I supplied for download earlier in this chapter.
<!-- SlidesJS Required: Start Slides --> <div id="slides"> <img src="img/example-slide-1.jpg" alt="Photo by: DK"> <img src="img/example-slide-2.jpg" alt="Photo by me!"> <img src="img/example-slide-3.jpg" alt="Photo by me!"> <img src="img/example-slide-4.jpg" alt="Photo by me!"> <img src="img/example-slide-5.jpg" alt="Photo by me!"> <a href="#" class="slidesjs-previous slidesjs-navigation"><i class="icon-chevron-left icon-large"></i></a> <a href="#" class="slidesjs-next slidesjs-navigation"><i class="icon-chevron-right icon-large"></i></a> </div> <!-- End SlidesJS Required: Start Slides -->
This is your instructor, David Karlins, and in this video I'm going to review some of what we did in Lesson 10, Chapter 3 to customize the slide show that we downloaded from SlidesJS.
Now this is a JavaScript widget, and typical of JavaScript widgets, there's editable HTML in it that allows us to customize the widget—in this case, to customize the slides that appear in the slide show, at least. So I followed all the steps in the lesson. I downloaded the images into my root folder, into an "img" subfolder.
However, instead of replacing the original images, I thought it would be more effective for this video if I create a second "img" folder that holds my images. And I'll leave the placeholder images in the original "img" folder. So I'm going to save this. And I'll add some alt text, like "Photo by DK." I'll save this.
Now when go I look at it in a browser, before I customized it, of course, I just had the placeholder images. But with it customized, I now see my own image first. All that's left is to replace the remaining images in the same way.
end transcript
Take a break if you need to, and then let's discuss how to make the slide show blend in to your website.
Integrating a jQuery Widget into a Website
We want the jQuery slide-show widget to look and feel as if it's a part of our site. At this stage, the widget we're using is beginning to look like a regular page in our website. But we can further integrate it into our site with elements like a navigation bar and some other links.
One way to integrate the widget is to add this code right before the close </div> tag that closes the #wrapper element near the end of the HTML:
<nav> <h2>Links: <a href="../../../index.html"> Home </a>| <a href="../../../feedback.html"> Feedback </a> | </h2> </nav>
This code provides links to other pages in your website and lets users navigate to your home page and other pages within your site.
And underneath the <nav> element, we can add a <footer> element, like this:
<footer> <h4>Slide show created by [your nickname]</h4> </footer>
This code adds a footer to the page—again making the slide show feel more like it's part of your larger website. It also provides a "credit" for the slide show.
Linking to Full-Sized Images
Here's something else we can do with HTML to enhance the slide show: Have the images that appear in the slide-show link to full-sized versions of those images. This is an accessible way to let visitors see full-size images if they wish to.
The jQuery slide-show template sizes images to fit in the slide display area. But those images then link to a full-sized version of themselves in a new browser window. To accomplish this, change the code to:
<a href="img/example-slide-1.jpg" target="_blank" title="click to open a full-sized image in a new browser window or tab"> <img src="img/example-slide-1.jpg" alt="Photo by: [your nickname]"> </a>
Linking slide-show images to full-sized pictures
Tweaking Example CSS
So far, we've customized the HTML code that came with the jQuery slide show by adding a <nav> element and a <footer> element. Let's impose our own CSS style sheet on the look and feel of the page. By the time we're done, the jQuery slide show will blend in perfectly with the rest of our site.
A few words of caution here: We're going to open and edit the example.css style sheet that came with the jQuery slide-show widget. We don't want to delete that file. Why not? When you get CSS files with a jQuery widget, the developer has usually built the widget in such a way that it requires both JavaScript and CSS files to work.
If we're cautious, we can edit the CSS we get. Here's what I mean by cautious:
Let's follow those steps for the example.css file that came with the SlidesJS widget. Find the selector for unvisited and visited links. It looks like this:
a:link, a:visited { color: #d22929; text-decoration: none; font-weight: 600; }
Change the link color to blue:
a:link, a:visited { color: blue; text-decoration: none; font-weight: 600; }
Save the example.css file, and test your page in a browser. It still works! So we can make another edit.
Find the selector for hovered and visited links. It looks like this:
a:hover, a:active { color: #9e2020; text-decoration: none; font-weight: 600; }
Change the color to purple, display underlining when a user hovers over a link, and delete the font-weight property:
a:hover, a:active { color: purple; text-decoration: underline; }
Again, save the example.css file, and test the page in your browser.
Customizing styles in the example style sheet
Going Beyond This Example
We dove fairly deep into one jQuery widget—the SlidesJS slide show. The point, though, was to get you comfortable with using jQuery widgets. You did one, but you can do more on your own.
Whether you grab a menu-bar widget, a tool-tip widget, another slide-show widget, or any of a growing library of free (and not free) jQuery widgets, the goal is the same: integrating them into your own site so that they look and feel like parts of one coherent website rather than a bunch of patched-together features.
How do you do that? It takes three steps:
I hope you can take the time to find useful widgets and integrate them into sites you create. Feel free to tell us about your successes and frustrations in the Discussion Area.
Summary
Let's review what you learned today.
A large and growing set of jQuery widgets is available online. You can use these widgets to add many of the most useful interactive objects to your website.
You don't need to know any jQuery or JavaScript to make jQuery widgets work. You can do all the customizing with HTML and CSS. And while there are often constraints on how much you can edit CSS, you can always edit the most prominent and defining CSS selectors. You do that by linking the HTML template that comes with the widget to your own CSS file. And you can edit the CSS file or files that come with the widget.
The world of jQuery widgets is open to you. There's no limit to the options for interactive and animated content at your site!
Let's not forget about site visitors who are using mobile devices. In Lesson 11, you'll build and customize a jQuery Mobile website. See you there!
Welcome to the widget factory! This site features more than a dozen widgets and effects you can use, including Accordion, Autocomplete, Button, Datepicker, Dialog, Menu, Progressbar, Slider, Spinner, Tabs, and Tooltip.
jQWidgets is a set of more than 30 jQuery widgets. It's not free (a license is in the range of $100), but you can check out the examples for free.
A Web developer presents his own set of favorite jQuery widgets, including some fun animation.
Q: I've heard Adobe has a new application called Edge Animate CC that creates JavaScript. Some people say Edge Animate is going to replace Flash. What do you know about that?
A: Adobe Flash and Adobe Edge Animate can both create JavaScript and HTML5 content, and they're both available as part of Adobe's Creative Cloud. You can see their demos at http://www.adobe.com/products/flash.html and http://html.adobe.com/edge/animate/.
I'll be interested to see whether Edge Animate catches on. It isn't that easy to generate usable, complex JavaScript widgets with it.
I'm not making predictions one way or the other on Edge Animate, but if it or JavaScript intrigues you, I encourage you to pursue the online classes Introduction to Adobe Edge Animate and Introduction to JavaScript. The same institution through which you signed up for this course most likely offers those online classes as well.
Q: Is JavaScript as good as the FlashPlayer plug-in?
A: That's an interesting question. While JavaScript is replacing the Flash plug-in as the main tool for website animation and interactivity, Flash software is now able to export HTML5 and JavaScript. So there's something of an apples-and-oranges element to comparing them. Right now, JavaScript doesn't provide quite the level of animation and effects that the Flash Player does . . . but it also doesn't require a plug-in to work within browsers.
I'd like you to create and customize a slide show for your site. It should include:
Upload the slide show, and please share a link to your uploaded page in the Discussion Area.
Back to top